package com.example.qxfw.rcyw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.rcyw.mapper.JobMakeMapper;
import com.example.qxfw.rcyw.pojo.JobMake;
import org.apache.poi.hssf.record.chart.DatRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class JobMakeServiceImpl implements com.example.qxfw.rcyw.service.JobMakeService {
    @Autowired
    private JobMakeMapper jobMakeMapper;

    @Override
    public List<JobMake> getList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        //queryWrapper.orderByDesc("recentmaketime");
        queryWrapper.orderByAsc("nametype");
        return jobMakeMapper.selectList(queryWrapper);
    }

    @Override
    public List<JobMake> getList1() {
        return jobMakeMapper.selectList(null);
    }

    @Override
    public Integer updateJobMake(Integer id, String recentmaketime) {
        JobMake jobMake = new JobMake();
        Timestamp timestamp = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(recentmaketime));
        jobMake.setRecentmaketime(timestamp);
       LambdaUpdateWrapper<JobMake> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(JobMake::getId, id);
        System.out.println(id);
        System.out.println( timestamp);
        int rows = jobMakeMapper.update(jobMake,updateWrapper);
        return rows;
    }

    @Override
    public Integer update(JobMake jobMake) {
        return jobMakeMapper.update(jobMake, Wrappers.<JobMake>lambdaUpdate()
                .eq(JobMake::getJobname,jobMake.getJobname())
                .eq(JobMake::getJobtype,jobMake.getJobtype()));
    }

    @Override
    public Integer update1(JobMake jobMake) {
        return jobMakeMapper.update(jobMake,Wrappers.<JobMake>lambdaUpdate()
                .eq(JobMake::getJobtype,jobMake.getJobtype()));
    }
}
